﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tasks.Dao;
using Tasks.Common;
using Tasks.Common.Entitys;
using System.Collections;
using MyLib.Util;

namespace Tasks.Business
{
    public class ArticleBLL
    {
        ArticleDao articleDao = new ArticleDao();

        public ArticleBLL()
        {

        }

        public ExecuteResult UpdateTestResult(int[] articleID, TestResult testResult, string tester)
        {
            foreach (int id in articleID)
            {
                articleDao.UpdateTestResult(id, (int)testResult, tester);
            }

            return new ExecuteResult() { ResultNo = 1 };
        }


        public Article GetArticleByID(int articleID)
        {
            return articleDao.Find(articleID);
        }

        public IList<Article> GetArticleByParentID(int articleID)
        {
            return articleDao.FindByParentID(articleID);
        }

        public IList<Article> GetArticleByReplyID(int articleID)
        {
            return articleDao.FindByReplyID(articleID);
        }

        public Article GetArticleByActionID(int ActionID,int OwnerID)
        {
            return articleDao.FindByActionID(ActionID, OwnerID);
        }

        /// <summary>
        /// 创建文章
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public ExecuteResult CreateArticle(Article article)
        {
            articleDao.Insert(article);

            #region "发送通知"


            #endregion

            return new ExecuteResult() { ResultNo = 1 };
        }

        public ExecuteResult ModifyArticle(Article article)
        {
            articleDao.Update(article);
            return new ExecuteResult() { ResultNo = 1 };
        }

        public ExecuteResult DeleteArticle(int articleID)
        {
            articleDao.Delete(articleID);
            return new ExecuteResult() { ResultNo = 1 };
        }

        public ExecuteResult ModifyAll(Article article, ReplyArticle reply)
        {
            articleDao.ModifyAll(article, reply);
            return new ExecuteResult() { ResultNo = 1 };
        }

        /// <summary>
        /// 快速查询文章
        /// </summary>
        /// <param name="ownerID"></param>
        /// <returns></returns>
        public IList<Article> QucikGetArticlesByOwnerID(int ownerID, int returnCount)
        {
            return articleDao.QuickFindByOwnerID(ownerID, returnCount);
        }

        /// <summary>
        /// 按条件搜索  
        /// </summary>
        /// <param name="condition">搜索条件</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowCount"></param>
        /// <returns></returns>
        public IList<Article> Search(Hashtable condition, int pageIndex, int pageSize, out int rowCount)
        {
            return articleDao.Search(condition, pageSize, pageIndex, out rowCount);
        }

        public IList<Article> GetArticleByTargetID(int targetID, int type)
        {
            return articleDao.FindByTargetID(targetID, type);
        }

        /// <summary>
        /// 能过类型查找article
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public IList<Article> GetArticlesByType(int type)
        {
            return articleDao.FindByArticleType(type);
        }

        public Article GetArticleByLatestDate(int type, int actionID,int OwnerID)
        {
            return articleDao.FindArticleByLatestDate(OwnerID, type, actionID);
        }

    

    }
}
